package main

import (
	hello "OldPackageTest/b_rpc_develop/a_helloworld/proto"
	"encoding/json"
	"fmt"
	"github.com/golang/protobuf/proto"
)

type Hello struct {
	Name    string   `json:"name"`
	Age     int      `json:"age"`
	Courses []string `json:"courses"`
}

func main() {
	req := hello.HelloRequest{
		Name:    "czc",
		Age:     18,
		Courses: []string{"go", "gin", "微服务"},
	}

	jsonStuct := Hello{
		Name:    "czc",
		Age:     18,
		Courses: []string{"go", "gin", "微服务"},
	}
	jsonRsp, _ := json.Marshal(jsonStuct)
	fmt.Println(string(jsonRsp))
	fmt.Println(len(jsonRsp))

	rsp, _ := proto.Marshal(&req)
	fmt.Println(string(rsp))
	fmt.Println(len(rsp))

	newReq := hello.HelloRequest{}
	_ = proto.Unmarshal(rsp, &newReq)
	fmt.Println(newReq)
	fmt.Println(newReq.Name)
}
